/**
 * Created by Coing on 2017/2/26.
 */

public class Solution1 {
    public boolean isPalindrome(String s) {
        boolean flag=false;
        //if(s==""||"".equals(s.trim())||" ".equals(s.trim())||s==" ")
        if( "".equals(s.trim()))
        {
            //flag=true;
            return true;
        }
        //过滤掉除数字和字母外的其他字符串
        String repstr = s.replaceAll("[^0-9a-zA-Z]","");
        System.out.println(repstr);
        String lowstr=repstr.toLowerCase();//结果存放
        // System.out.println(test);

        char[] old=lowstr.toCharArray();//转换为字符
        StringBuilder reverse=new StringBuilder();
        //去掉空格
        for(int i=old.length-1;i>=0;i--){
            reverse.append(old[i]);
        }
        System.out.println("反转后："+reverse);

        if(lowstr.equals(reverse.toString())){
            flag = true;
        }else {
            flag = false;
        }
        return flag;
    }

    public static void main(String[] args) {
        Solution1 solution = new Solution1();
        System.out.println(solution.isPalindrome(""));
        System.out.println(solution.isPalindrome("A man, a plan, a canal: Panama"));
        System.out.println(solution.isPalindrome("ab"));


    }
}

